package edu.ynu.onlinesqltool.action;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import edu.ynu.onlinesqltool.dao.SQLExcution;

public class UpdateAction implements IAction {

	public void execute(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		String sql = req.getParameter("sql");
		try {
			int effectedColumns = SQLExcution.update(sql);
			req.setAttribute("effectedColumns", effectedColumns);
			RequestDispatcher dispater=req.getRequestDispatcher(resp.encodeURL("/success.jsp"));
			dispater.forward(req,resp);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			req.setAttribute("error", e);
			RequestDispatcher dispater=req.getRequestDispatcher(resp.encodeURL("/error.jsp"));
			dispater.forward(req,resp);
		}

	}

}
